//
//  CYYYSManageVC.m
//  CreditAddressBook
//
//  Created by mosu on 2016/12/16.
//  Copyright © 2016年 Lee. All rights reserved.
//

#import "CYYYSManageVC.h"
#import "CYYYSZDDetailVC.h"
#import "DCPaymentView.h"
#import "CYUser.h"
#import "MBProgressHUD+LE.h"
#import "UIAlertView+Block.h"
#import "CYHttpTool.h"
#import "CYLoginHttpTool.h"
#import "CYDES3Util.h"
#import "CYJsonInfo.h"
#import "NSObject+MJKeyValue.h"

@interface CYYYSManageVC ()
@property (weak, nonatomic) IBOutlet UIImageView *yysstatueImageView;  
@property (weak, nonatomic) IBOutlet UIImageView *yysshimingImageView;
@property (weak, nonatomic) IBOutlet UILabel *yysshoufeiLab;
@property (weak, nonatomic) IBOutlet UILabel *yysLab;

@end

@implementation CYYYSManageVC

- (void)viewDidLoad {
    [super viewDidLoad];
    //注册通知
     CYLog(@"dic = %@",self.mesdic);
     CYLog(@"sttr = %@",self.yysstatueStr);
     CYLog(@"fxstr = %@",self.yysfxStr);
     
     _yysshoufeiLab.text =  [NSString stringWithFormat:@"第三方平台收费%@元",[self.mesdic objectForKey:@"yys"]];
     _yysLab.text = [NSString stringWithFormat:@"第三方平台收费%@元",[self.mesdic objectForKey:@"fx"]];
     
     if (self.yysstatueStr && self.yysstatueStr.intValue == 0) {
          _yysshimingImageView.hidden = YES;
          
     }else{
          _yysshimingImageView.hidden = NO;
     }
     
     if (self.yysfxStr && self.yysfxStr.intValue == 0) {
          _yysstatueImageView.hidden = YES;
          
     }else{
          _yysstatueImageView.hidden = NO;
     }
     
     

     
     // Do any additional setup after loading the view from its nib.
}


- (IBAction)yysClick:(id)sender {
     
          UIAlertView *firstalert = [[UIAlertView alloc]initWithTitle:@"即将进行运营商认证" message:_yysshoufeiLab.text delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"确认", nil];
          [firstalert showAlertViewWithCompleteBlock:^(NSInteger buttonIndex) {
               if (buttonIndex == 1) {
     
                    DCPaymentView *payAlert = [[DCPaymentView alloc]init];
                    payAlert.detail = @"请输入交易密码";
                    NSString *aount = [self. mesdic objectForKey:@"yys"];
                    payAlert.amount = aount.doubleValue;
                    [payAlert show];
                    payAlert.completeHandle = ^(NSString *inputPwd) {
                         NSString *desstr = [CYDES3Util encrypt:inputPwd];
                         CYUser *user = [CYLoginHttpTool userData].user;
                         [MBProgressHUD showMessage:nil toView:self.view];
                         [CYHttpTool postWithURL:[CYURL shared].saveJuHeMno params:@{@"userId":user.userId,@"token":user.token,@"dealCode":desstr} success:^(id json) {
                              [MBProgressHUD hideHUDForView:self.view animated:YES];
                              CYJsonInfo *jsoninfo = [CYJsonInfo objectWithKeyValues:json];
                              CYAlertView(jsoninfo.message);
                              if (jsoninfo.isSuccess) {
                                   //
                                   self.yysstatueStr = @"1";
                              }
     
                         } failure:^(NSError *error) {
                              [MBProgressHUD hideHUDForView:self.view animated:YES];
                              CYLog(@"error = %@",error);
                              CYAlertView(@"网络错误");
     
                         }];
                         
                    };
     
                    
               }
               
               
          }];

     
     
}
- (IBAction)yysfxClick:(id)sender {
     CYYYSZDDetailVC *yyszd = [[CYYYSZDDetailVC alloc]init];
     [self.navigationController pushViewController:yyszd animated:YES];
     
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
